<?php

require_once 'db.php';

class works extends db {

    public $start;
    public $end;

    public function select($page = null) {
        $this->connect();
        $begin = ($page - 1) * PER_PAGE;
        $query = "SELECT * FROM works limit " . $begin . "," . PER_PAGE;
        $works = $this->query($query);
        return $works;
    }

    public function count() {
        $this->connect();
        $query = "SELECT * FROM works";
        $works = $this->query($query);
        return count($works);
    }

    public function select_edit($page = NULL, $id = NULL) {
        $this->connect();
        $where = "";
        if (!empty($id))
            $where = "where id=$id";
        $limit = "";
        if (!empty($page))
            $limit = 'limit ' . $begin . ',' . PER_PAGE;
        $begin = ($page - 1) * PER_PAGE;
        $query = "SELECT * FROM works $where $limit";
        $result = mysql_query($query);
        $result = mysql_fetch_assoc($result);
        return $result;
    }

    public function update($array = null) {
        $query = "Update works set name='" . $array['name'] .
                "', description='" . $array['description'] .
                "', image='" . $array['image'] .
                "' where id=" . $array['id'];
        mysql_query($query);
        if (mysql_query($query))
            echo "ok";
        else
            echo "fail";
    }

}

?>